/*
Daniel Mena
08825
laboratorio 1
programa que simula un radio con una misma interfas para todos
*/


import java.text.DecimalFormat;


public class EnamoRadio implements NuestraInterfaz{

    private static final boolean fm = false;
	//Datos de instancia (atributos)
    private double  station;
    private boolean on, Fm; // on/off
    private String Onoff, FmAm;
    DecimalFormat decimalesR = new DecimalFormat("0.##");
    private double fmMemory[] = new double[12];		// Arreglo para almacenar en memoria estaciones de FM
	private double amMemory[] = new double[12];		// Arreglo para almacenar en memoria estaciones de AM
	
	
	    //Constructor - inicializa objeto (predefinido)
    public EnamoRadio(){
	
 
        Onoff=" Apagado";
		FmAm = "Fm";
		station = 87.9;
	}

  
	
    public void onoff(){

        on=!on;

        if (on == true){
            this.Onoff= " Encendido";
            }
        else{
            this.Onoff= " Apagado";
            }

    }
		

    public void cambio1(){

        Fm=!Fm;

        if(Fm == true){
            this.FmAm=" En FM";
            this.station=87.9;
            }
        else{
            this.FmAm=" En AM";
            this.station=530;
            }
    }

    public void avanzar(){
    	if (on){
			if (Fm){
				if (station != 107.9){
					station = station + 0.2;
				}else {
					station = 89.7;
				}
			}else{
				if (station != 1610){
					station = station + 10.0;
				}else {
					station = 530.0;
				}
			}
		}
	}
    public void retroceder(){
		if (on){
			if (Fm){
				if (station != 87.9){ 
					station = station - 0.2;
				}else{ 
					station = 107.9;
				}
			}else {
				if (station != 530.0) { 
					station = station - 10.0;	
				}else { 
					station = 1610.0;
				}
			}
		}
	}
	

    public void ifo(){

        if(Fm == true){
        if (station<87.9)
                station=107.9;
        if (station>107.9)
                station=87.9;
        }
        else{

        if (station<530)
                station=1610;
        if (station>1610)
                station=530;
        }		

    }

	
	public void save(int boton){
		if (on){
			if (Fm){
				fmMemory[boton] = station;
			}else {
				amMemory[boton] = station;
			}
		}
	}
		

// Guardar en la memoria[pos] la estacion actual  

	public void push(int botons){
		if (fm) {
			station = fmMemory[botons];
		}else {
			station = amMemory[botons];
		}
	}


// Cargar la estacion almacenda en la memoria[pos] *
	

   public boolean getOn(){
		return on;
	}  // devuelve si está encendido o pagado
	 
   public boolean getFM(){
		return Fm;
	}   //  ver si esta en FM, 
	
	
  
  public void setEmisora(double newEmisora){
	this.station=newEmisora;
  
  }

   
   public double getEmisora(){
		return station;
	}// devuelve la emisora
	

    public String toString(){
        String estatus;
        estatus  = "**    ON/OFF: " + Onoff +" **\n";
        estatus += "**    Estacion: " + decimalesR.format(getEmisora()) +"**\n";
        estatus += "**    FM/AM: " + FmAm  + "**\n";

        return estatus;
    }

	public boolean power() {
		return false;
	}
	
	public boolean cambio() {
		return false;
	}
	public void fw() {
		
	}
	public void bw() {
		
	}
	public void store(int boton) {
	
	}
	public void select(int botons) {
	
	}
	public void salir() {
	
	}
	
}